package mosdi.tools;

import java.util.Arrays;

import mosdi.fa.Alphabet;
import mosdi.fa.IIDTextModel;
import mosdi.paa.HorspoolPAA;
import mosdi.paa.SundayPAA;
import mosdi.util.Iupac;
import mosdi.util.Log;

public class HorspoolAnalysis {

	public static void usage() {
		System.err.println("Usage: HorspoolAnalysis <pattern> <textlength>");
		System.exit(-1);
	}
	
	public static void main(String[] args) {
		if (args.length!=2) usage();
		String stringPattern = args[0];
		int textLength = Integer.parseInt(args[1]);
		Alphabet alphabet = Iupac.getDnaAlphabet();
		int[] pattern = alphabet.buildIndexArray(stringPattern);
		System.out.println("Analyzed pattern: "+stringPattern);
		System.out.println("Textlength: "+textLength);
		System.out.println("Textmodel: uniform i.i.d.");
		Log.setTimingActive(true);
		// ---------- Horspool ---------------
		System.out.println("---------- Horspool -------------");
		Log.startTimer();
		HorspoolPAA horspoolPaa = new HorspoolPAA(new IIDTextModel(alphabet.size()), textLength, pattern);
		double[] horspoolValueDistribution = horspoolPaa.computeValueDistribution(textLength);
		double[] horspoolCostDistribution = horspoolPaa.costDistribution(horspoolValueDistribution);
		Log.stopTimer("Compute cost distribution (Horspool)");
		System.out.println(Arrays.toString(horspoolCostDistribution));
		// ---------- Sunday ---------------
		System.out.println("---------- Sunday -------------");
		Log.startTimer();
		SundayPAA sundayPaa = new SundayPAA(new IIDTextModel(alphabet.size()), textLength, pattern);
		double[] sundayValueDistribution = sundayPaa.computeValueDistribution(textLength);
		double[] sundayCostDistribution = sundayPaa.costDistribution(sundayValueDistribution);
		Log.stopTimer("Compute cost distribution (Sunday)");
		System.out.println(Arrays.toString(sundayCostDistribution));
	}

}
